package org.elfen.service;

import org.elfen.sys.entity.SysUser;
import org.elfen.sys.facade.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;

import feign.hystrix.FallbackFactory;

@FeignClient(name="sys-service",fallbackFactory=SysUserClinet.SysUserServiceFallBackFactory.class)
public interface SysUserClinet extends SysUserService{
	
	/**
	 * Feign Hystrix回退<br>
	 * Hystrix 能使你的系统在出现依赖服务失效的时候，通过隔离系统所依赖的服务，
	 * 防止服务级联失败，同时提供失败回退机制，更优雅地应对失效
	 */
	@Component
	class SysUserServiceFallBackFactory implements FallbackFactory<SysUserClinet>{

		@Override
		public SysUserClinet create(final Throwable e) {
			return new SysUserClinet(){
				private final Logger log = LoggerFactory.getLogger(SysUserService.class);

				@Override
				public String hello(String name) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return null;
				}

				@Override
				public SysUser insert(SysUser sysUser) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return null;
				}

				@Override
				public boolean deleteById(String id) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return false;
				}

				@Override
				public boolean flagDeleteById(String id) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return false;
				}

				@Override
				public SysUser updateById(SysUser sysUser) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return null;
				}

				@Override
				public SysUser selectById(String id) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return null;
				}

				@Override
				public SysUser selectOne(SysUser sysUser) {
					log.info("服务调用异常，进入Hystrix回退逻辑！",e);
					return null;
				}
			};
		}
		
	}
}
